package com.bdv.md.dao.impl;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.bdv.md.dao.DmTblDao;
import com.bdv.md.en.ConstantValues;
import com.bdv.md.model.DmTbl;
import com.bdv.md.model.MapTbl;
@Repository
public class DmTblDaoImpl extends AbstractDaoImpl<DmTbl, Integer> implements DmTblDao {

	public DmTblDaoImpl() {
		super(DmTbl.class);
	}

	public List<DmTbl> findByRange(MapTbl mapTbl, Timestamp start, Timestamp end) {

        Criteria criteria = getCurrentSession().createCriteria(DmTbl.class);
        criteria.add(Restrictions.eq("mapTbl", mapTbl));
        criteria.add(Restrictions.between("timeStamp", start, end));
    	criteria.add(Restrictions.eq("tipeReading", ConstantValues.READING_TYPE_PERIODIC.getCode())); 
    	criteria.addOrder(Order.asc("timeStamp"));
        return criteria.list() ;
	}
}
